package hesso.smartdraw.ch.soap;

import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class SOAPHelper {

	private static final String NAMESPACE = "http://www.jrw.ch/firefly/";
	private static final String URL = "http://www.jrw.ch/firefly/webservice.php";
	
	public static String loginCheck(String username, String password){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/loginCheck";
			final String METHOD_NAME = "loginCheck";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("username", username);
			request.addProperty("password", password);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}

	public static int loginCheckId(String username, String password){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/loginCheckId";
			final String METHOD_NAME = "loginCheckId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("username", username);
			request.addProperty("password", password);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return 0;
		}
	}

	public static boolean registerClient(String email){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/registerUser";
			final String METHOD_NAME = "registerUser";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("email", email);

			Object result = request(request, SOAP_ACTION);
			
			return (Boolean) result;

		} catch (Exception e) {
			return false;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getLayers(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getLayersName";
			final String METHOD_NAME = "getLayersName";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;
			
		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getDevices(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getDevicesJava";
			final String METHOD_NAME = "getDevicesJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getUnits(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getUnits";
			final String METHOD_NAME = "getUnits";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getInputs(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getInputs";
			final String METHOD_NAME = "getInputs";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getOutputs(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getOutputs";
			final String METHOD_NAME = "getOutputs";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getBuildingsByUser(int userId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getBuildingsByUserJava";
			final String METHOD_NAME = "getBuildingsByUserJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("userId", userId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getBuildingById(int buildingId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getBuildingByIdJava";
			final String METHOD_NAME = "getBuildingByIdJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("buildingId", buildingId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getLevelsByBuilding(int buildingId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getLevelsByBuildingJava";
			final String METHOD_NAME = "getLevelsByBuildingJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("buildingId", buildingId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getRoomsByLevel(int levelId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getRoomsByLevelJava";
			final String METHOD_NAME = "getRoomsByLevelJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("levelId", levelId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getWallsByRoom(int roomId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getWallsByRoomJava";
			final String METHOD_NAME = "getWallsByRoomJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("roomId", roomId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getInstalledByWall(int wallId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getInstalledByWallJava";
			final String METHOD_NAME = "getInstalledByWallJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("wallId", wallId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<SoapObject> getConsumationsByInstalled(int installedId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getConsumationsByInstalled";
			final String METHOD_NAME = "getConsumationsByInstalled";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("installedId", installedId);
			
			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(request);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

	        Vector<SoapObject> result = (Vector<SoapObject>)soapEnvelope.getResponse();
			
	        
			return result;

		} catch (Exception e) {
			return null;
		}
	}
	
	public static String addBuilding(int buildingId, String buildingName, int userId, int buildingVersion){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addBuildingJava";
			final String METHOD_NAME = "addBuildingJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("buildingId", buildingId);
			request.addProperty("buildingName", buildingName);
			request.addProperty("userId", userId);
			request.addProperty("lastChange", buildingVersion);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String addLevel(int levelId, String levelName, int levelLevel, int buildingId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addLevelJava";
			final String METHOD_NAME = "addLevelJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("levelId", levelId);
			request.addProperty("levelName", levelName);
			request.addProperty("levelLevel", levelLevel);
			request.addProperty("buildingId", buildingId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String addRoom(int roomId, String roomName, int levelId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addRoomJava";
			final String METHOD_NAME = "addRoomJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("roomId", roomId);
			request.addProperty("roomName", roomName);
			request.addProperty("levelId", levelId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String addWall(int wallId, String wallName, int wallX1, int wallX2, int wallY1, int wallY2, int wallHeight, int wallDepth, int roomId, int wallType){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addWallJava";
			final String METHOD_NAME = "addWallJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("wallId", wallId);
			request.addProperty("wallName", wallName);
			request.addProperty("wallX1", wallX1);
			request.addProperty("wallX2", wallX2);
			request.addProperty("wallY1", wallY1);
			request.addProperty("wallY2", wallY2);
			request.addProperty("wallHeight", wallHeight);
			request.addProperty("wallDepth", wallDepth);
			request.addProperty("roomId", roomId);
			request.addProperty("wallType", wallType);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String addInstalled(int installedId, String installedName, int installedX, int installedY, int installedHeight, int installedWidth, int deviceId, int wallId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addInstalledJava";
			final String METHOD_NAME = "addInstalledJava";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("installedId", installedId);
			request.addProperty("installedName", installedName);
			request.addProperty("installedX", installedX);
			request.addProperty("installedY", installedY);
			request.addProperty("installedHeight", installedHeight);
			request.addProperty("installedWidth", installedWidth);
			request.addProperty("deviceId", deviceId);
			request.addProperty("wallId", wallId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String addConsumation(int consumationId, int consumationValue, int installedId, int unitId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/addConsumation";
			final String METHOD_NAME = "addConsumation";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("consumationId", consumationId);
			request.addProperty("consumationValue", consumationValue);
			request.addProperty("installedId", installedId);
			request.addProperty("unitId", unitId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateBuilding(String buildingName, int userId, int buildingId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateBuilding";
			final String METHOD_NAME = "updateBuilding";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("buildingName", buildingName);
			request.addProperty("userId", userId);
			request.addProperty("id", buildingId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateLevel(String levelName, int levelLevel, int buildingId, int levelId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateLevel";
			final String METHOD_NAME = "updateLevel";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("levelName", levelName);
			request.addProperty("levelLevel", levelLevel);
			request.addProperty("buildingId", buildingId);
			request.addProperty("id", levelId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateRoom(String roomName, int levelId, int roomId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateRoom";
			final String METHOD_NAME = "updateRoom";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("roomName", roomName);
			request.addProperty("levelId", levelId);
			request.addProperty("id", roomId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateWall(String wallName, int wallX1, int wallX2, int wallY1, int wallY2, int wallHeight, int wallDepth, int roomId, int wallType, int wallId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateWall";
			final String METHOD_NAME = "updateWall";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("wallName", wallName);
			request.addProperty("wallX1", wallX1);
			request.addProperty("wallX2", wallX2);
			request.addProperty("wallY1", wallY1);
			request.addProperty("wallY2", wallY2);
			request.addProperty("wallHeight", wallHeight);
			request.addProperty("wallDepth", wallDepth);
			request.addProperty("roomId", roomId);
			request.addProperty("wallType", wallType);
			request.addProperty("id", wallId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateInstalled(String installedName, int installedX, int installedY, int installedHeight, int installedWidth, int deviceId, int wallId, int installedId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateInstalled";
			final String METHOD_NAME = "updateInstalled";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("installedName", installedName);
			request.addProperty("installedX", installedX);
			request.addProperty("installedY", installedY);
			request.addProperty("installedHeight", installedHeight);
			request.addProperty("installedWidth", installedWidth);
			request.addProperty("deviceId", deviceId);
			request.addProperty("wallId", wallId);
			request.addProperty("id", installedId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String updateConsumation(int consumationValue, int installedId, int unitId, int consumationId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/updateConsumation";
			final String METHOD_NAME = "updateConsumation";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("consumationValue", consumationValue);
			request.addProperty("installedId", installedId);
			request.addProperty("unitId", unitId);
			request.addProperty("consumationId", consumationId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeBuilding(int id){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeBuilding";
			final String METHOD_NAME = "removeBuilding";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("id", id);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeLevel(int id){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeLevel";
			final String METHOD_NAME = "removeLevel";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("id", id);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeRoom(int id){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeRoom";
			final String METHOD_NAME = "removeRoom";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("id", id);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeWall(int id){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeWall";
			final String METHOD_NAME = "removeWall";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("id", id);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeInstalled(int id){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeInstalled";
			final String METHOD_NAME = "removeInstalled";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("id", id);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static String removeConsumation(int consumationId){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/removeConsumation";
			final String METHOD_NAME = "removeConsumation";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("consumationId", consumationId);

			Object result = request(request, SOAP_ACTION);
			
			return result.toString();

		} catch (Exception e) {
			return e.toString();
		}
	}
	
	public static int getNewBuildingId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewBuildingId";
			final String METHOD_NAME = "getNewBuildingId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}
	
	public static int getNewLevelId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewLevelId";
			final String METHOD_NAME = "getNewLevelId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}
	
	public static int getNewRoomId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewRoomId";
			final String METHOD_NAME = "getNewRoomId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}
	
	public static int getNewWallId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewWallId";
			final String METHOD_NAME = "getNewWallId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}	
	
	public static int getNewInstalledId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewInstalledId";
			final String METHOD_NAME = "getNewInstalledId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}
	
	public static int getNewConsumationId(){
		try {
			final String SOAP_ACTION = "http://www.jrw.ch/firefly/webservice.php/getNewConsumationId";
			final String METHOD_NAME = "getNewConsumationId";
			
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			Object result = request(request, SOAP_ACTION);
			
			return Integer.parseInt(result.toString());

		} catch (Exception e) {
			return -1;
		}
	}
	
	public static Object request(SoapObject request, String SOAP_ACTION){		
		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		soapEnvelope.dotNet = true;
		soapEnvelope.setOutputSoapObject(request);
		
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		try{
			androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
			Object result = soapEnvelope.getResponse();
			
			return result;
		}
		catch(Exception e){
			return e.toString();
		}
	}
}